#ifndef _COS_SESSION_H
#define _COS_SESSION_H

#include "buffer.h"
#include <map>
using namespace std;


class Session
{
public:
	Session();
	~Session();
	void Init();
	virtual void OnRecvPack() = 0;
	virtual void OnConnect() = 0;
	virtual void OnDisconnect() = 0;
	int GetFd();
	void SetFd(int fd);
	Buffer* GetRecvBuf();
public:
	bool m_IsFree;

private:
	int m_fd;
	Buffer m_RecvBuf;
	Buffer m_SendBuf;
};

class SessionMgr
{
public:
	SessionMgr();
	~SessionMgr();
	virtual bool Init(size_t NumSession) = 0;
	Session * GetSession(int fd);
	Session * CreateSession(int fd);
	void FreeSession(int fd);
private:
	map<int, Session *> m_Sessions;
	Session * m_FreeSessions;
	size_t m_MaxFreeSession;
};

#endif
